<?php

namespace Book\Model;

use Think\Model;

class BookChapterModel extends Model {


    public function CreateDefaultChapter($bookid){
        $data['bookid'] = $bookid;
        $data['filename'] = 'SUMMARY.md';
        $data['content'] = base64_encode('* [空白目录](default.md)');
        $this->add($data);
        return true;
    }

    public function CreateChapter($bookid, $info){
        $data['bookid'] = $bookid;
        $data['filename'] = $info['filename'];
        $data['content'] = $info['content'];
        if($info['sha']){
            $data['sha'] = $info['sha'];
        }
        if($info['blob_sha']){
            $data['blob_sha'] = $info['blob_sha'];
        }
        
        return $this->add($data);
    }

    public function updateChapter($bookid, $filename, $info){
        $map['bookid'] = $bookid;
        $map['filename'] = $filename;
        // var_dump($map, $info);exit;

        return $this->where($map)->save($info);
        // return $this->add($data);
    }

}

?>